﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WTwitter.Model.Framework;
using WTwitter.Model.UserData;
using System.Windows.Media.Imaging;
using WTwitter.ViewModel.Utility;

namespace WTwitter.ViewModel {
	public enum FriendType {
		Friend,
		Following,
		Followed,
		None,
	}

	sealed public class UserViewModel : ViewModelBase, IEquatable<UserViewModel> {
		private IUser _user;
		private IUser _clientUser;
		/// <summary>
		/// コンストラクタ
		/// </summary>
		/// <param name="user">このクラスの元となるデータ</param>
		/// <param name="ClientUser">フォロー情報などの対象のユーザー（このユーザーとの関係を表示する）</param>
		public UserViewModel(IUser user, IUser clientUser) 
			: base (user.ScreenName) {
			_user = user;
			_clientUser = clientUser;
			if (_user.Id.HasValue) {
				IsFollowed = _clientUser.FollowersIds.Contains(_user.Id.Value);
				IsFollowing = _clientUser.FollowingIds.Contains(_user.Id.Value);
			}

		}

		public IUser User {
			get { return _user; }
		}

		public long? Id {
			get { return _user.Id; }
		}

		public string ScreenName {
			get { return _user.ScreenName; }
		}

		public string Name {
			get { return _user.Name; }
		}

		public string ProfileImageUrl {
			get { return _user.ProfileImageUrl; }
		}

		public FriendType FriendType {
			get {
				if (IsFollowing) {
					if (IsFollowed) return FriendType.Friend;
					else return FriendType.Following;
				} else {
					if (IsFollowed) return FriendType.Followed;
					else return FriendType.None;
				}

			}
		}

		public string Description {
			get { return _user.Description; }
		}

		public bool IsFollowing { get; private set; }

		public bool IsFollowed { get; private set; }

		public bool IsFriend {
			get { return IsFollowed && IsFollowing; }
		}
		
		#region IEquatable<UserViewModel> メンバ

		public bool Equals(UserViewModel other) {
			return this.ScreenName.Equals(other.ScreenName);
		}

		#endregion
	}
}
